﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DingHeng.TransportationManagement.Business;
using DingHeng.TransportationManagement.WebCommon;

namespace DingHeng.TransportationManagement.WebSite
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                HttpContext.Current.Session.Clear();
            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            DingHeng.TransportationManagement.Entity.User currentUser = null;
            try
            {
                currentUser  = new UserBiz().Login(this.txtUserName.Text.Trim(), this.txtPWD.Text);
            }
            catch (Exception ex)
            {
                Response.Redirect("/Login.aspx");
            }
            if (currentUser != null)
            {
                WebContext.Current.CurrentUser = currentUser;
                Response.Redirect("/Biz/VehicleDispatchForm.aspx", true);
            }
            else
            { 
                //TODO:用户不存在或密码错误
            }
        }
    }
}